package com.ssy.lingxi.product.controller.pc.material;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.model.request.material.*;
import com.ssy.lingxi.product.model.resp.material.MaterialProcessDetailVO;
import com.ssy.lingxi.product.model.resp.material.MaterialProcessPageQueryVO;
import com.ssy.lingxi.product.model.resp.material.MaterialProcessRelMaterialGroupQueryVO;
import com.ssy.lingxi.product.model.resp.material.MaterialProcessRelMaterialQueryVO;
import com.ssy.lingxi.product.model.resp.platform.PlatformBaseMaterialProcessVO;
import com.ssy.lingxi.product.service.material.IMaterialProcessService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 商品能力 - 物料流程规则配置
 * @author 彭冬冬
 * @version 2.0.0
 * @date 2022/3/28 13:41
 */
@RestController
@RequestMapping("/product/material/process")
public class MaterialProcessController extends BaseController {

    @Resource
    private IMaterialProcessService service;

    /**
     * 分页查询物料流程规则
     * @param request 请求
     * @param pageVO 分页查询条件
     * @return 查询结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<MaterialProcessPageQueryVO>> pageMaterialProcesses(HttpServletRequest request, @Valid MaterialProcessPageVO pageVO) {
        return service.pageMaterialProcesses(getSysUser(request), pageVO);
    }

    /**
     * 新增物料流程规则页面 - 查询基础物料流程列表
     * @param request 请求域
     * @return 查询结果
     */
    @GetMapping("/base/list")
    public Wrapper<List<PlatformBaseMaterialProcessVO>> listBaseMaterialProcesses(HttpServletRequest request) {
        return service.listBaseMaterialProcesses(getSysUser(request));
    }

    /**
     * 物料流程规则新增那种
     * @param request 请求域
     * @param saveVO 物料流程规则
     * @return 新增结果
     */
    @PostMapping("/save")
    public Wrapper<Void> save(HttpServletRequest request, @RequestBody @Valid MaterialProcessVO saveVO) {
        return service.save(getSysUser(request), saveVO);
    }

    /**
     * 查询物料流程规则详情
     * @param request 请求域
     * @param processId 流程id
     * @return 查询结果
     */
    @GetMapping("/get")
    public Wrapper<MaterialProcessDetailVO> getInfo(HttpServletRequest request, @RequestParam("processId") Long processId) {
        return service.getInfo(getSysUser(request), processId);
    }

    /**
     * 查询物料组勾选树结构
     * @param request 请求域
     * @param processId 物料流程id
     * @return 查询结果
     */
    @GetMapping("/tree/rel/material/group")
    public Wrapper<List<MaterialProcessRelMaterialGroupQueryVO>> treeRelMaterialGroup(HttpServletRequest request, @RequestParam("processId") Long processId) {
        return service.treeRelMaterialGroup(getSysUser(request), processId);
    }

    /**
     * 分页查询部分物料
     * @param request 请求域
     * @param pageVO 分页查询请求
     * @return 查询结果
     */
    @GetMapping("/page/rel/material")
    public Wrapper<List<MaterialProcessRelMaterialQueryVO>> pageRelMaterial(HttpServletRequest request, @Valid MaterialProcessRelMaterialPageVO pageVO) {
        return service.listRelMaterial(getSysUser(request), pageVO);
    }

    /**
     * 修改物料流程规则
     * @param request 请求域
     * @param updateVO 修改数据
     * @return 修改结果
     */
    @PostMapping("/update")
    public Wrapper<Void> update(HttpServletRequest request, @RequestBody @Valid MaterialProcessUpdateVO updateVO) {
        return service.update(getSysUser(request), updateVO);
    }

    /**
     * 修改物料流程状态
     * @param request 请求域
     * @param updateStatusVO 修改物料状态
     * @return 修改结果
     */
    @PostMapping("/update/status")
    public Wrapper<Void> updateStatus(HttpServletRequest request, @RequestBody @Valid MaterialProcessUpdateStatusVO updateStatusVO) {
        return service.updateStatus(getSysUser(request), updateStatusVO);
    }

    /**
     * 删除物料流程规则
     * @param request 请求域
     * @param processId 要删除的物料流程规则id
     * @return 删除结果
     */
    @GetMapping("/delete")
    public Wrapper<Void> delete(HttpServletRequest request, @RequestParam("processId") Long processId) {
        return service.delete(getSysUser(request), processId);
    }

    /**
     * 查询物料是否配置了业务流程
     * @param request 请求域
     * @param queryVO 查询参数
     * @return 查询结果
     */
    @GetMapping("/is/exist/material/process")
    public Wrapper<Boolean> isExistMaterialProcess(HttpServletRequest request, @Valid MaterialProcessRelVO queryVO) {
        return service.isExistMaterialProcess(getSysUser(request), queryVO);
    }

}
